package com.example.myapplication;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;

public class RateListActivity4 extends AppCompatActivity {
    Handler handler;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_list4);

        ArrayList<HashMap<String,String>> listItems = new ArrayList<HashMap<String, String>>();
        //for (int i = 0; i < 10; i++) {
        //    HashMap<String, String> map = new HashMap<String, String>();
        //    map.put("ItemTitle", "Rate： " + i);
        //    map.put("ItemDetail", "detail" + i);
         //   listItems.add(map);}
        SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItems,
                R.layout.list_item,
                new String[] { "ItemTitle", "ItemDetail" },
                new int[] { R.id.itemTitle, R.id.itemDetail }

        );
        ListView mylistview=findViewById(R.id.mylist);
        mylistview.setAdapter(listItemAdapter);
        //mylistview.setEmptyView(findViewById(R.id.nodata));
        mylistview.setVisibility(View.INVISIBLE);
        ProgressBar bar=findViewById(R.id.progressbar);


        handler=new Handler(Looper.myLooper()){
            public void handleMessage(@NonNull Message msg){
                if(msg.what==11){
                    Toast.makeText(RateListActivity4.this,"数据已更新",Toast.LENGTH_SHORT).show();
                    ArrayList<HashMap<String,String>> list2 = (ArrayList<HashMap<String, String>>) msg.obj;

                    MyAdapter myAdapter=new MyAdapter(RateListActivity4.this,R.layout.list_item,list2);
                    mylistview.setAdapter(myAdapter);
                    mylistview.setVisibility(View.VISIBLE);
                    bar.setVisibility(View.GONE);

                }
                super.handleMessage(msg);

            }


        };
        RateActivity mythread=new RateActivity();
        mythread.setHandler(handler);
        Thread t=new Thread(mythread);
        t.start();


    }
}